<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="品种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pz">
              <a-input v-model="model.pz" placeholder="请输入品种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生育期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="syq">
              <j-dict-select-tag type="list" v-model="model.syq" dictCode="syq" placeholder="请选择生育期" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="阶段名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jdm">
              <a-input v-model="model.jdm" placeholder="请输入阶段名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
           <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="beginTime">
              <!-- <j-date placeholder="请选择开始时间" v-model="model.beginTime"  format="MM-DD" style="width: 100%" /> -->
              <a-date-picker  placeholder="请选择开始时间" v-model="model.beginTime" format="MM-DD" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
           <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime">
              <!-- <j-date placeholder="请选择结束时间" v-model="model.endTime"  format="MM-DD" style="width: 100%" /> -->
              <a-date-picker placeholder="请选择结束时间" v-model="model.endTime" format="MM-DD" style="width: 100%" />
            </a-form-model-item>
            
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="龄期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="age">
              <j-dict-select-tag type="list" v-model="model.age" dictCode="age" placeholder="请选择龄期" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="灌溉措施" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ggcs">
              <a-textarea v-model="model.ggcs" rows="4" placeholder="请输入灌溉措施" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="施肥措施" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfcs">
              <a-textarea v-model="model.sfcs" rows="4" placeholder="请输入施肥措施" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="植保措施" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zbcs">
              <a-textarea v-model="model.zbcs" rows="4" placeholder="请输入植保措施" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="积温带" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jwd">
              <j-dict-select-tag type="list" v-model="model.jwd" dictCode="jwd" placeholder="请选择积温带" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'RpkForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/wiis/rpk/add",
          edit: "/wiis/rpk/edit",
          queryById: "/wiis/rpk/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>